//
//  YSFeedbackItemFrame.m
//  Yueshi
//
//  Created by Northwan on 15/8/7.
//  Copyright (c) 2015年 悦食中国. All rights reserved.
//

#import "YSFeedbackItemFrame.h"

@implementation YSFeedbackItemFrame


-(void)setMsg:(YSFeedbackItem *)msg{
    _msg = msg;
    //名称
    CGSize nameSize = CGSizeZero;
    CGFloat nameX;
    NSString *name = @"悦";
    nameSize = [name sizeWithFont:SYS_FONT(CONTENT_SIZE)];
    if(msg.fromType == FeedbackMsgFromSendType){
        nameX = SCREENW - YSPublicXInset- nameSize.width;
    }else{
        nameX = YSPublicXInset;
    }
    self.nameFrame = CGRectMake(nameX, YSPublicXInset*2, nameSize.width, nameSize.height);
    
    //正文
    CGSize maxSize = CGSizeMake(SCREENW-nameSize.width-YSPublicXInset*6, MAXFLOAT);
    CGFloat contentY = YSPublicXInset;
    CGFloat contentX = 0;
    CGSize contentSize = [msg.content sizeWithFont:SYS_FONT(CONTENT_SIZE) constrainedToSize:maxSize];
    CGFloat contentW = contentSize.width + YSPublicXInset * 2;
    CGFloat contentH = contentSize.height + YSPublicXInset * 2;
    
    if(msg.fromType == FeedbackMsgFromSendType){
        contentX = nameX - contentW - YSPublicXInset;
    }else{
        contentX = CGRectGetMaxX(self.nameFrame)+YSPublicXInset;
    }
    
    self.contentFrame = CGRectMake(contentX, contentY, contentW, contentH);
    
    //cell高度
    CGFloat maxNameY = CGRectGetMaxY(self.nameFrame);
    CGFloat maxContentY = CGRectGetMaxY(self.contentFrame);
    
    self.cellHeight = MAX(maxNameY, maxContentY) + YSPublicXInset;
    
    self.frame = CGRectMake(0, 0, SCREENW,self.cellHeight);
}

@end
